﻿#pragma once

#include <QWidget>
#include "ui_TestWindow.h"
#include <QCloseEvent>
#include <QString>
#include <thread>
#include <chrono>
#include <QDebug>
#include <QTimer>
#include "../format/YDemuxer.h"
#include "../format/YMuxer.h"
#include "../codec/VideoReScaler.h"
#include "../codec/YDecoder.h"
#include "../codec/YEncoder.h"
#include "../task/YTools.h"


class TestWindow : public QWidget
{
	Q_OBJECT

public:
	void OnStartPlay();
	void Release();
	TestWindow(QWidget *parent = nullptr);
	~TestWindow();

protected:
	// 重写关闭事件处理函数
	void closeEvent(QCloseEvent* event) override;

signals:
	void updateUi(AVFrame *frame);

public slots:
	void onSelectedFile();
	void onStartPlayVideo();
	void OnUpdateUi(AVFrame *frame);
	void OnTimeout();

private:
	Ui::TestWindow ui;
	QString filePath;
	std::unique_ptr<std::thread> renderThread;
	bool isRunning = false;
	YDemuxer* demuxer = nullptr;
	YDecoder* decoder = nullptr;
	VideoReScaler* videoReScaler = nullptr;
	std::mutex m_mutex;
	QTimer* timer = nullptr;
	YAVFrameList frameList;
};
